package Advance;

//import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @Description:通过接口进行数据库连接测试
 * @Author:AMark
 * @Date: 11/13/2023
 */
//public class ConDataS {
//    //DruidDataSource是阿里巴巴提供的数据库连接池
//    public static DruidDataSource getDataSource(String driverClassName, String url, String username, String password) {
//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setDriverClassName(driverClassName);
//        dataSource.setUrl(url);
//        dataSource.setUsername(username);
//        dataSource.setPassword(password);
//        //设置最大活动连接数
//        dataSource.setMaxActive(10);
//        dataSource.setInitialSize(5);
//        dataSource.setMinIdle(2);
//        return dataSource;
//    }
//
//    public static void main(String[] args) {
//        String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
//        String URL = "jdbc:mysql://localhost:3306/hw;?serverTimezone=UTC";
//        String USER = "root";
//        String PASSWORD = "zhc20040309";
//        DataSource dataSource = getDataSource(JDBC_DRIVER,URL,USER,PASSWORD);
//        Connection conn = null;
//        try {
//            conn = dataSource.getConnection();
//            System.out.println("连接成功!" + conn);
//        } catch (SQLException e) {
//            System.out.println("数据库连接失败！");
//        }
//    }
//}
